package com.shanghaionstar.carmanage;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.annotation.ContentView;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.onstar.cn.map.common.LocationType;
import com.onstar.cn.map.common.PoiItemInfo;
import com.shanghaionstar.R;
import com.shanghaionstar.nav.service.AbstractMapActivity;
import com.shanghaionstar.utils.FinalConstants;
import com.shanghaionstar.utils.MapHandler;

/**
 * Created by 7828wc on 2016/6/29.
 */
@ContentView(com.onstar.cn.framework.R.layout.fragment_container)
public class ChargingPileActivity extends AbstractMapActivity {
    private FragmentManager fragmentManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fragmentManager = getSupportFragmentManager();

        setmMyLocationArrow(R.drawable.nav_map_marker_my);
        setmPoiLocationArrow(R.drawable.nav_map_marker_poi);

        String fragmentFlag = getIntent().getStringExtra(FinalConstants.JUMP_FLAG);
        changeFragment(fragmentFlag);

    }

    public void changeFragment(String fragmentFlag) {
        try {
            Class<?> clazz = Class.forName(fragmentFlag);
            if (clazz.newInstance() instanceof Fragment) {
                Fragment fragment = (Fragment) clazz.newInstance();
                if (!CommonUtil.isNull(getIntent().getExtras())) {
                    fragment.setArguments(getIntent().getExtras());
                }
                changeFragment(fragment, clazz, false);
            } else {
                Intent intent = new Intent(getApplicationContext(), clazz);
                startActivity(intent);
                finish();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public BasePresenter getPresenter() {
        return null;
    }

    @Override
    public void onBackPressed() {
        if (fragmentManager.getBackStackEntryCount() == 1) {
            this.finish();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public void initMapHandler(MapHandler mapHandler) {

    }

    @Override
    public void showPoiToMap(PoiItemInfo poiItemInfo, LocationType locationType) {

    }

    /**
     * 地图点的图标
     *
     * @return
     */
    @Override
    public int getmMyLocationArrow() {
        return R.drawable.nav_map_marker_my;
    }

    /**
     * POI location
     */
    @Override
    public int getmPoiLocationArrow() {
        return R.drawable.nav_map_marker_poi;
    }
}
